package com.installtime.demo.config;

import com.installtime.demo.Interceptor.GlobalExceptionInterceptor;
import com.installtime.demo.controller.HelloController;
import com.installtime.demo.controller.TestController;
import com.installtime.demo.controller.UserController;
import com.installtime.demo.model.User;
import com.jfinal.config.*;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.template.Engine;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @Classname JFinalConfiguration
 * @Description TODO
 * @Date 6/29/2020 1:10 PM
 * @Created by W.Z
 */
public class JFinalConfiguration extends JFinalConfig {

    @Override
    public void configConstant(Constants me) {
        me.setDevMode(true);
    }
    @Override
    public void configRoute(Routes me) {
        me.add("/hello", HelloController.class);
        me.add("/test", TestController.class);
        me.add("/user", UserController.class);
    }
    @Override
    public void configEngine(Engine engine) {

    }
    @Override
    public void configPlugin(Plugins plugins) {
        //添加druid插件
        DruidPlugin druidPlugin=new DruidPlugin(
                "jdbc:mysql://127.0.0.1:3306/express_auth?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowMultiQueries=true",
                "test","test");
        plugins.add(druidPlugin);
        // 配置ActiveRecord插件
        ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
        // 映射blog 表到 Blog模型
        arp.addMapping("t_user", User.class);
        arp.setShowSql(true);
        plugins.add(arp);
    }
    @Override
    public void configInterceptor(Interceptors interceptors) {

        interceptors.add(new GlobalExceptionInterceptor());
    }
    @Override
    public void configHandler(Handlers handlers) {

    }


}
